<?php
$this->breadcrumbs=array(
	TextbooksModule::t('Change Campus') => Yii::app()->createUrl('/textbooks/selectUniversity'),
	TextbooksModule::t($university->name),
);?>

<form class="well form-inline h-textbooks-form-search-department">
	<?php $arrDepartments = CHtml::listData($departments, 'id', 'name');
	$this->widget('bootstrap.widgets.BootTypeahead', array(
		'id' => 'input_name',
		'options'=>array(
			'source'=>array_values($arrDepartments),
			'items'=>4,
			'matcher'=>"js:function(item) {
				return ~item.toLowerCase().indexOf(this.query.toLowerCase());
			}",
		),
		'htmlOptions' => array(
			'class' => 'span3',
			'placeholder' => 'Search for department here...',
			'autocomplete' => 'off',
		),
	)); ?>
	<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'icon'=>'search', 'label'=>'Go')); ?>
	<span class="errorMessage errorField_name"></span>
	<?php // $this->widget('bootstrap.widgets.BootButton', array('type'=>'primary', 'icon'=>'plus', 'label'=>'Add new department', 'htmlOptions'=>array('class'=>'pull-right', 'data-target'=>'#modalAddDepartment', 'data-toggle'=>'modal'))); ?>
	<?php // $this->widget('bootstrap.widgets.BootButton', array('type'=>'primary', 'icon'=>'plus', 'label'=>'Post a new book', 'htmlOptions'=>array('class'=>'pull-right', 'data-target'=>'#modalPostBook', 'data-toggle'=>'modal'))); ?>
	<a class="pull-right btn btn-primary" href="<?php echo Yii::app()->createUrl('/textbooks/book/post', array('university_id'=>$university->id)); ?>"><i class="icon-plus icon-white"></i> Post a new book</a>
</form>

<?php /* $this->beginWidget('bootstrap.widgets.BootModal', array('id'=>'modalAddDepartment')); ?>
<form class="h-textbooks-form-add-department form-horizontal modal-form" action="<?php echo Yii::app()->createUrl('/textbooks/department/add', array('university_id'=>$university->id)); ?>" method="POST">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">&times;</a>
		<h3>Add new department</h3>
	</div>
	<div class="modal-body">
		<fieldset>
			<div class="control-group">
				<?php echo CHtml::label(TextbooksModule::t('Name'), 'TextbookDepartment_name', array('class'=>'control-label')); ?>
				<div class="controls">
					<?php echo CHtml::textField('TextbookDepartment[name]', '', array('class'=>'span3')); ?>
					<div class="errorMessage errorField_name"></div>
				</div>
			</div>
		</fieldset>
	</div>
	<div class="modal-footer">
		<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Add', 'icon'=>'ok')); ?>
		<?php $this->widget('bootstrap.widgets.BootButton', array('label'=>'Close', 'icon'=>'remove', 'url'=>'#', 'htmlOptions'=>array('data-dismiss'=>'modal'))); ?>
	</div>
</form>
<?php $this->endWidget();*/ ?>

<?php /*$this->beginWidget('bootstrap.widgets.BootModal', array('id'=>'modalPostBook')); ?>
<form class="h-textbooks-form-post-book form-horizontal modal-form" action="<?php echo Yii::app()->createUrl('/textbooks/book/post'); ?>" method="POST">
	<?php echo CHtml::hiddenField('TextbookBook[thumbnail]', ''); ?>
	<?php echo CHtml::hiddenField('TextbookBook[google_api_json]', ''); ?>
	<div class="modal-header">
		<a class="close" data-dismiss="modal">&times;</a>
		<h3>Post a new book</h3>
	</div>
	<div class="modal-body">
		<fieldset>
			<div class="control-group">
				<?php echo CHtml::label(TextbooksModule::t('Department'), 'TextbookBook_department_id', array('class'=>'control-label')); ?>
				<div class="controls">
					<?php echo CHtml::dropDownList('TextbookBook[department_id]', '', CMap::mergeArray(array(''=>'[Select one]'), $arrDepartments), array('class'=>'span3')); ?>
					<div class="errorMessage errorField_department_name"></div>
				</div>
			</div>
			
			<div class="control-group">
				<?php echo CHtml::label(TextbooksModule::t('ISBN'), 'TextbookBook_isbn', array('class'=>'control-label')); ?>
				<div class="controls">
					<?php echo CHtml::textField('TextbookBook[isbn]', '', array('class'=>'span3')); ?>
					<a title="Search Information" class="h-textbooks-books-link-search-isbn" href="#"><i class="icon-search"></i></a>
					<div class="errorMessage errorField_isbn"></div>
				</div>
			</div>
			
			<div class="h-textbooks-div-hidden" style="display:none">
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Course'), 'TextbookBook_course_name', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[course_name]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_name"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Title'), 'TextbookBook_title', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[title]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_title"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Price'), 'TextbookBook_price', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[price]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_price"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Phone'), 'TextbookBook_phone', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[phone]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_phone"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Author'), 'TextbookBook_author', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[author]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_author"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Description'), 'TextbookBook_description', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textArea('TextbookBook[description]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_description"></div>
					</div>
				</div>
			</div>
		</fieldset>
	</div>
	<div class="modal-footer">
		<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Add', 'icon'=>'ok', 'htmlOptions'=>array('disabled'=>true))); ?>
		<?php $this->widget('bootstrap.widgets.BootButton', array('label'=>'Close', 'icon'=>'remove', 'url'=>'#', 'htmlOptions'=>array('data-dismiss'=>'modal'))); ?>
	</div>
</form>
<?php $this->endWidget();*/ ?>

<?php if ($departments) : ?>
	<ul>
		<?php foreach ($departments as $department) : ?>
		<li><?php echo CHtml::link("{$department->name} ({$department->books})", array('/textbooks/book/list/department_id/' . $department->id), array('title' => $department->name)); ?></li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>